const express=require("express");
const handleDB=require("../db/handleDB");
const common=require("../utils/common");
const constant=require("../utils/constant");
const md5=require("md5");
const Captcha=require("../utils/captcha");
const keys = require("../utils/keys");
const jwt=require("jsonwebtoken");
require("../utils/filter");

const router=express.Router();


router.get("/seah/",(req,res)=>{
    (async function(){

        let query=req.query;
        let seahtext=query.seahtext;

        let userInfo=await common.getUser(req,res);

        let number="";
        if(userInfo[0]){
            let indentCounts=await handleDB(res,"indent","sql","数据库查询出错",`select count(*) from indent where user_id=${userInfo[0].user_id} and is_order=0`);
            number=indentCounts[0]["count(*)"];
        }
        let salesOrder=await handleDB(res,"commodity","find","查询数据库出错","1 order by sales_volume desc limit 6")
        let data={
            user_info:userInfo[0]?{
                nick_name:userInfo[0].nick_name,
                head_url:userInfo[0].head_url?userInfo[0].head_url:"/images/worm.jpg"
            }:false,
            number:number,
            seahtext:seahtext,
            salesOrder:salesOrder
        };
        res.render("./web_seah",data);
    })();
})

module.exports=router